package homework1

import java.util

import org.apache.kafka.clients.producer.{KafkaProducer, ProducerConfig}
import org.apache.kafka.common.serialization.StringSerializer

// 用于获取producer
object ProducerUtils {
  val brokers = "linux100:9092,linux101:9092,linux102:9092"
  val conf = new util.HashMap[String, Object]()
  conf.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, brokers)
  conf.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, classOf[StringSerializer])
  conf.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, classOf[StringSerializer])
  val kafkaProducer = new KafkaProducer[String, String](conf)

  def getProducer: KafkaProducer[String, String] = kafkaProducer
}
